package com.updesignsz.api.mapper;

import com.updesignsz.commom.entity.News;
import com.updesignsz.commom.entity.Projects;
import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 新闻
 * Creation date 2020-8-8 15:00:07
 */
@Repository
@Mapper
public interface NewsMapper {

    @Select({"<script>",
            "select `id`,`created_date`,`updated_date`, `type`, `title`, `cover`, `cover_thumbnail`, `release_date`, `sequence`, `is_removed`  from news ",
            "<where>",
            "<if test=\"type != null and type != '' \" >AND type = #{type}</if>",
            "<if test=\"title != null and type != '' \" >AND title like '%${title}%'</if>",
            "AND is_removed = 0",
            "</where>",
            "order by sequence desc, created_date desc",
            "</script>"
    })
    List<News> listPageAll(Map<String, Object> map);


    @Select({"<script>",
            "select *  from news ",
            "<where>",
            "<if test=\"type != null and type != '' \" >AND type = #{type}</if>",
            "<if test=\"title != null and type != '' \" >AND title like '%${title}%'</if>",
            "AND is_removed = 0",
            "</where>",
            "order by sequence desc, created_date desc",
            "</script>"
    })
    List<News> listAll(JSONObject json);


    @Select("select * from news where id = #{id}")
    News getById(@Param("id") Integer id);
}